<!--{template /module/admin/view/head}-->
<div id="left_layout">
	<div id="main_content" class="container-fluid">
		<!--{template /module/admin/view/head_nav}-->
		<div class="row-fluid">
			<div class="well widget">
				<div class="widget-header">
		            <a href="{$ADMIN_SCRIPT}/cms/category">{lang cms.category.view.header}</a>
		            <!--{loop $crumbs $crumb}-->
		            / <a href="{$ADMIN_SCRIPT}/cms/category&parentid={$crumb[CATEGORYID]}">{$crumb[CNAME]}</a>
		            <!--{/loop}-->
	            </div>
	            
		        <div class="widget-content">
		        	<div class="action-wrapper">
						<div class="pull-left">
							<a href="javascript:void(null);" id="btn_submit" class="btn btn-small btn-primary" {$dispatches[operations][edit]}>{lang admin.operation.submit}</a>
							<a href="javascript:void(null);" id="btn_delete_list" class="btn btn-small" {$dispatches[operations][delete]}>{lang admin.operation.delete}</a>
							<a href="{$ADMIN_SCRIPT}/cms/category/_add&parentid={$_var[gp_parentid]}" {$dispatches[operations][add]} class="btn btn-small">{lang cms.category.view.operation.add}</a>
						</div>
					</div>
					
					<hr/>
			        <form id="frm_grid" name="frmGrid" action="{$ADMIN_SCRIPT}/cms/category&parentid={$_var[gp_parentid]}" method="post">
			        <table class="table table-hover">
				        <thead>
				        	<tr>
					        	<th width="20"><input type="checkbox" class="fancy" name="cbxAll"/></th>
					            <th width="55">{lang cms.category.view.th.displayorder}</th>
					            <th width="100">{lang cms.category.view.th.identity}</th>
					            <th>{lang cms.category.view.th.cname}</td>
					            <th width="120">{lang cms.category.view.th.editer}/{lang cms.category.view.th.edittime}</th>
					            <th width="40">{lang cms.category.view.th.audit}</th>
					            <th width="60">{lang cms.category.view.th.children}</th>
					            <th width="90">{lang cms.category.view.th.operation}</th>
				        	</tr>
				        </thead>
				        <!--{loop $categories $_loop $category}-->
				        <tr class="item-row">
				        	<td>
				                <!--{if $category['CHILDREN'] == 0}-->
				                <input type="checkbox" class="fancy" cname="{$category[CNAME]}" name="cbxItem[]" value="{$category[CATEGORYID]}" />
				                <!--{/if}-->
				            </td>
				             <td>
				             	<input type="text" class="input-mini" name="displayorder[{$category[CATEGORYID]}]" value="{$category[DISPLAYORDER]}" />
				            </td>
				            <td>
				            	<input type="text" class="input-small" name="identity[{$category[CATEGORYID]}]" value="{$category[IDENTITY]}" />
				            </td>
				            <td>
				                <a href="{$ADMIN_SCRIPT}/cms/category&parentid={$category[CATEGORYID]}" class="f14">{$category[CNAME]}</a>
				                <p class="muted thin">
				                	{echo cutstr($category['COMMENT'], 80);}
				                </p>
				                <p class="muted thin f10">
				                	<!--{if $category['URL']}-->
				                	{$category[URL]}
				                	<!--{else}-->
				                	{lang cms.category.view.th.url}
				                	<!--{/if}-->
				                </p>
				            </td>
				            <td class=" f10">
				            	{$category[EDITER]}<br/>
				            	{echo $category['EDITTIME'] ? date('Y-m-d H:i', strtotime($category[EDITTIME])) : '';}
				            </td>
				            <td class=" f10">
				            	<!--{if $category['ISAUDIT']}-->
			                	{lang cms.category.view.th.audit.yes}
			                	<!--{else}-->
			                	{lang cms.category.view.th.audit.no}
			                	<!--{/if}-->
				            </td>
				            <td class="center">
				                <a href="{$ADMIN_SCRIPT}/cms/category&parentid={$category[CATEGORYID]}">{$category[CHILDREN]}</a>
				            </td>
				            <td class="left">
				                <a class="btn btn-mini btn-primary" href="{$ADMIN_SCRIPT}/cms/category/_update&id={$category[CATEGORYID]}&parentid={$_var[gp_parentid]}" {$dispatches[operations][edit]}>{lang admin.operation.edit}</a>
				                <!--{if $category['CHILDREN'] == 0}-->
				                <a class="btn btn-mini btn-delete" cname="{$category[CNAME]}" data="{$category[CATEGORYID]}" href="javascript:void(null);" {$dispatches[operations][delete]}>{lang admin.operation.delete}</a>
				                <!--{/if}-->
				            </td>
				        </tr>
				        <!--{/loop}-->
				        <!--{if $count == 0}-->
				        <tr>
				            <td colspan="8">
				                * {lang admin.operation.empty}
				            </td>
				        </tr>
				        <!--{/if}-->
				    </table>
				    </form>
				</div>
			</div>
		</div>
	</div>
</div>

<script>
$(function(){
	$('.fancy').uniform();
	
	$('#btn_submit').click(function(){
		$('#frm_grid').submit();
	});
	
	$('#btn_delete_list').click(function(){
		if($("#frm_grid input[name='cbxItem[]']:checked").length > 0){
			var tempHTML = '<p>';
			$("#frm_grid input[name='cbxItem[]']:checked").each(function(){
				tempHTML += $(this).attr('cname') + '； ';
			});
			
			tempHTML += '</p>';
			
			$.dialog({submit:'{lang admin.operation.delete}', message:'<p>{lang cms.category.view.operation.delete.message}</p>' + tempHTML, callback:function(){
				$('#modal_dialog .btn-primary').click(function(){
					$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/cms/category&do=delete_list&parentid={$_var[gp_parentid]}');
					$('#frm_grid').submit();
				});
			}});
		}else $.dialog({message:'{lang cms.category.view.operation.empty}'});
	});
	
	$("#frm_grid input[name='cbxAll']").click(function(){
		if(this.checked){
			$('#frm_grid .item-row').addClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', true).parent().addClass('checked');
		}else{
			$('#frm_grid .item-row').removeClass('warning');
			$("#frm_grid input[name='cbxItem[]']").attr('checked', false).parent().removeAttr('class');
		}
	});
	
	$("#frm_grid input[name='cbxItem[]']").click(function(){
		if(this.checked) $(this).parent().parent().parent().parent().addClass('warning');
		else $(this).parent().parent().parent().parent().removeClass('warning');
	});
	
	$("#frm_grid .btn-delete").click(function(){
		var menuid = $(this).attr('data');
		var tempHTML = '<p>' + $(this).attr('cname') + '； </p>';
		$.dialog({submit:'{lang admin.operation.delete}', message:'<p>{lang cms.category.view.operation.delete.message}</p>' + tempHTML, callback:function(){
			$('#modal_dialog .btn-primary').click(function(){
				$('#frm_grid').attr('action', '{$ADMIN_SCRIPT}/cms/category&do=delete&id=' + menuid + '&parentid={$_var[gp_parentid]}');
				$('#frm_grid').submit();
			});
		}});
	});
});
</script>
<!--{template /module/admin/view/foot}-->